#pragma once

#include "Timer.h"
#include "Socket.h"

typedef struct ip_address {
	unsigned char byte1;
	unsigned char byte2;
	unsigned char byte3;
	unsigned char byte4;

} ip_address;

typedef struct client_s {
	struct client_s* next;

	unsigned long ip;
	unsigned short port;

	Broady::SocketPtr node;
	unsigned long node_ip;
	unsigned short node_port;

	unsigned int shakeID;
	unsigned int lastPingID;

	Broady::Timer pingTimeout;
	Broady::Timer pingInterval;

} client_t;

/* IPv4 header */
typedef struct ip_header {
	unsigned char	ver_ihl;		/* Version (4 bits) + Internet header length (4 bits) */
	unsigned char	tos;			/* Type of service */
	unsigned short tlen;			/* Total length */
	unsigned short identification; /* Identification */
	unsigned short flags_fo;		/* Flags (3 bits) + Fragment offset (13 bits) */
	unsigned char	ttl;			/* Time to live */
	unsigned char	proto;			/* Protocol */
	unsigned short crc;			/* Header checksum */
	ip_address	saddr;		/* Source address */
	ip_address	daddr;		/* Destination address */
	unsigned int	op_pad;			/* Option + Padding */

} ip_header;

/* UDP header*/
typedef struct udp_header {
	unsigned short sport;			/* Source port */
	unsigned short dport;			/* Destination port */
	unsigned short len;			/* Datagram length */
	unsigned short crc;			/* Checksum */

} udp_header;

extern unsigned short ip_sum_calc( unsigned short len_ip_header, unsigned char buff[] );
extern void OutputMessage( const char* const fmt, ... );
